<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>GEN30</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="ScoregensTop.html" title="Score Statements and GEN Routines" />
    <link rel="prev" href="GEN28.html" title="GEN28" />
    <link rel="next" href="GEN31.html" title="GEN31" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">GEN30</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="GEN28.html">Prev</a> </td>
          <th width="60%" align="center">Score Statements and GEN Routines</th>
          <td width="20%" align="right"> <a accesskey="n" href="GEN31.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="GEN30"></a>
      <div class="titlepage"></div>
      <a id="IndexGEN30" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">GEN30</span>
        </h2>
        <p>GEN30 — 
      Generates harmonic partials by analyzing an existing table.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215354048"></a>
        <h2>Description</h2>
        <p>
      Extracts a range of harmonic partials from an existing waveform.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215355328"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>f</strong></span> # time size  30  src  minh maxh [ref_sr] [interp]</pre>
      </div>
      <div class="refsect1">
        <a id="idp215425328"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>src</em></span> -- source ftable
    </p>
        <p>
      <span class="emphasis"><em>minh</em></span> -- lowest harmonic number
    </p>
        <p>
      <span class="emphasis"><em>maxh</em></span> -- highest harmonic number
    </p>
        <p>
      <span class="emphasis"><em>ref_sr</em></span> (optional) -- maxh is scaled by (sr / ref_sr). The default value of ref_sr is sr. If <span class="emphasis"><em>ref_sr</em></span> is zero or negative, it is now ignored.
    </p>
        <p>
      <span class="emphasis"><em>interp</em></span> (optional) -- if non-zero, allows changing the amplitude of the lowest and highest harmonic partial depending on the fractional part of <span class="emphasis"><em>minh</em></span> and <span class="emphasis"><em>maxh</em></span>. For example, if <span class="emphasis"><em>maxh</em></span> is 11.3 then the 12th harmonic partial is added with 0.3 amplitude. This parameter is zero by default.
    </p>
        <p>
      <span class="emphasis"><em>GEN30</em></span> does not support tables with an extended guard point (ie. table size = power of two + 1). Although such tables will work both for input and output, when reading source table(s), the guard point is ignored, and when writing the output table, guard point is simply copied from the first sample (table index = 0). 
    </p>
        <p>
      The reason of this limitation is that <span class="emphasis"><em>GEN30</em></span> uses FFT, which requires power of two table size.  <a class="link" href="GEN32.html" title="GEN32"><em class="citetitle">GEN32</em></a> allows using linear interpolation for resampling and phase shifting, which makes it possible to use any table size (however, for partials calculated with FFT, the power of two limitation still exists).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215435616"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the GEN30 routine. It uses the files <a class="ulink" href="examples/gen30.csd" target="_top"><em class="citetitle">gen30.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp215437472"></a>
          <p class="title">
            <strong>Example 1117. Example of the GEN30 routine.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o gen30.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">;a simplified example of Istvan Varga</span>
<span class="ohdr">sr</span> <span class="op">=</span>  44100
<span class="ohdr">ksmps</span> <span class="op">=</span>  32
<span class="ohdr">nchnls</span> <span class="op">=</span>  2
<span class="ohdr">0dbfs</span>   <span class="op">=</span> 1

isaw	<span class="ohdr">ftgen</span> 1, 0, 16384, 7, 1, 16384, <span class="op">-</span>1						<span class="comment">;sawtooth wave </span>
iFM	<span class="ohdr">ftgen</span> 3, 0, 4096, 7, 0, 512, 0.25, 512, 1, 512, 0.25, 512,	\
			     0, 512, <span class="op">-</span>0.25, 512, <span class="op">-</span>1, 512, <span class="op">-</span>0.25, 512, 0			<span class="comment">;FM waveform</span>
iAM	<span class="ohdr">ftgen</span> 4, 0, 4096, 5, 1, 4096, 0.01						<span class="comment">;AM waveform</span>
iEQ	<span class="ohdr">ftgen</span> 5, 0, 1024, 5, 1, 512, 32, 512, 1						<span class="comment">;FM to EQ</span>
isine	<span class="ohdr">ftgen</span> 6, 0, 1024, 10, 1								<span class="comment">;sine wave</span>

<span class="op">/</span><span class="op">*</span> generate bandlimited sawtooth waves <span class="op">*</span><span class="op">/</span>
i0	<span class="op">=</span>  0
<span class="olabel">loop1</span><span class="op">:</span>
imaxh	<span class="op">=</span>  <span class="ohdr">sr</span> <span class="op">/</span> (2 <span class="op">*</span> 440.0 <span class="op">*</span> <span class="opc">exp</span>(<span class="opc">log</span>(2.0) <span class="op">*</span> (i0 <span class="op">-</span> 69) <span class="op">/</span> 12))
i_	<span class="ohdr">ftgen</span> i0 <span class="op">+</span> 10, 0, 4096, <span class="op">-</span>30, 1, 1, imaxh					<span class="comment">;use gen 30</span>
i0	<span class="op">=</span>  i0 <span class="op">+</span> 1
	<span class="octrl">if</span> (i0 <span class="op">&lt;</span> 127.5) <span class="octrl">igoto</span> <span class="olabel">loop1</span>

<span class="oblock">instr</span> 1

kcps	<span class="op">=</span>  440.0 <span class="op">*</span> <span class="opc">exp</span>(<span class="opc">log</span>(2.0) <span class="op">*</span> (p4 <span class="op">-</span> 69) <span class="op">/</span> 12)					<span class="comment">;note frequency</span>
klpmaxf	<span class="opc">limit</span> p5 <span class="op">*</span> kcps, 1000.0, 12000.0						<span class="comment">;lowpass max. frequency</span>

kfmd1	<span class="op">=</span>  0.03 <span class="op">*</span> kcps									<span class="comment">;FM depth in Hz</span>
kamfr	<span class="op">=</span>  kcps <span class="op">*</span> 0.02									<span class="comment">;AM frequency</span>
kamfr2	<span class="op">=</span>  kcps <span class="op">*</span> 0.1

kfnum	<span class="op">=</span>  (10 <span class="op">+</span> 69 <span class="op">+</span> 0.5 <span class="op">+</span> 12 <span class="op">*</span> <span class="opc">log</span>(kcps <span class="op">/</span> 440.0) <span class="op">/</span> <span class="opc">log</span>(2.0))				<span class="comment">;table number</span>
aenv	<span class="opc">linseg</span> 0, p3<span class="op">*</span>0.25, 1, p3<span class="op">*</span>0.75, 0						<span class="comment">;amp. envelope</span>

asig	<span class="opc">oscbnk</span> kcps, 0.0, kfmd1, 0.0, 40, 200, 0.1, 0.2, 0, 0, 144,	      \
		0.0, klpmaxf, 0.0, 0.0, 1.5, 1.5, 2, kfnum, 3, 0, 5, 5, 5
asig	<span class="op">=</span> asig <span class="op">*</span> aenv<span class="op">*</span>.03
<span class="opc">outs</span> asig, asig

<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">s</span>
<span class="stamnt">i</span> 1 0 6 41 10
<span class="stamnt">i</span> 1 0 6 60
<span class="stamnt">i</span> 1 0 6 65
<span class="stamnt">i</span> 1 0 6 69
<span class="stamnt">s</span>
<span class="stamnt">i</span> 1 0 6 41 64
<span class="stamnt">i</span> 1 0 6 60
<span class="stamnt">i</span> 1 0 6 65
<span class="stamnt">i</span> 1 0 6 69

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp215441760"></a>
        <h2>Credits</h2>
        <p>Author: Istvan Varga</p>
        <p>New in version 4.16</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="GEN28.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="ScoregensTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="GEN31.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">GEN28 </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> GEN31</td>
        </tr>
      </table>
    </div>
  </body>
</html>
